package cn.nawang.ebeim.api.controller;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cn.nawang.ebeim.api.comm.PageList;
import cn.nawang.ebeim.api.comm.Pages;
import cn.nawang.ebeim.api.domain.FileChangeLog;
import cn.nawang.ebeim.api.service.FileChangeLogService;
import cn.nawang.ebeim.api.utils.Constant;

/**
 * @ClassName: FileChangeLogController
 * @Description: TODO
 * @author fanyb
 * @date Aug 18, 2015 2:37:30 PM
 * @version v1.0
 */
@RestController
public class FileChangeLogController {
  private static final Logger LOG = LoggerFactory.getLogger(FileChangeLogController.class);

  @Autowired
  private FileChangeLogService fileChangeLogService;

  /**
   * 
   * @author fanyb
   * @Description: 添加文件变更日志
   * @param fileChangeLog 文件变更日志对象
   * @return Map<String,Object> 返回结果
   * @date Aug 18, 20152:40:54 PM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/token/file_change_log/add", method = RequestMethod.POST)
  public Map<String, Object> addFileChangeLog(FileChangeLog fileChangeLog) {
    LOG.debug("/token/file_change_log/add {}", fileChangeLog);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("code", Constant.CODE_ERROR);
    boolean isSuccess = fileChangeLogService.addFileChangeLog(fileChangeLog);
    if (isSuccess) {
      map.put("code", Constant.CODE_SUCCESS);
    }
    LOG.debug("addFileChangeLog {}", map);
    return map;
  }

  /**
   * @author 张建峰
   * @Description: 分页查询
   * @param @param fileChangeLog
   * @param @param page
   * @param @return
   * @return Map<String,Object>
   * @date 2015年9月25日下午4:50:58
   *
   * @修改人 张建峰
   * @修改日期
   */
  @RequestMapping(value = "/token/file_change_log/list", method = RequestMethod.GET)
  public Map<String, Object> getFileChangeLogs(FileChangeLog fileChangeLog, Pages page) {
    LOG.debug("/token/file_change_log/list {}", fileChangeLog);
    Map<String, Object> map = new HashMap<String, Object>();
    PageList list = fileChangeLogService.getFileChangeLogs(fileChangeLog, page);
    map.put("code", Constant.CODE_SUCCESS);
    map.put("list", list);
    LOG.debug("getFileChangeLogs {}", fileChangeLog);
    return map;
  }

  /**
   * @author 张建峰
   * @Description: 根据dsId删除
   * @param @param dsId
   * @param @return
   * @return Map<String,Object>
   * @date 2015年9月28日上午8:32:53
   *
   * @修改人 张建峰
   * @修改日期
   */
  @RequestMapping(value = "/token/file_change_log/delete/dsid", method = RequestMethod.GET)
  public Map<String, Object> deleteByDsId(String dsId) {
    LOG.debug("/token/file_change_log/delete/dsid {}", dsId);
    Map<String, Object> map = new HashMap<String, Object>();
    fileChangeLogService.deleteLogs(dsId);
    map.put("code", Constant.CODE_SUCCESS);
    LOG.debug("deleteByDsId {}", dsId);
    return map;
  }
}
